<?php
namespace app\admin\controller;



class Fx extends Base
{

    public function setting(){
        if(request()->isPost()){
            $level1=i("level1","等级一不能为空","int");
            $level2=i("level2","等级二不能为空","int");
            c("fx",["level1"=>$level1,"level2"=>$level2]);
            $this->success("设置成功");
        }
        $info=c("fx");
        $this->assign("info",$info);
        return view();
    }

    public function lists(){
        $list = model('fxGoods')->join('goods g','fx_goods.goods_id = g.id')->select();
        $this->assign('list',$list);
        return view();
    }

    public function edit(){
        $id = i('id');
        $edit = model('fxGoods')->where('goods_id',$id)->find();
        $this->assign('edit',$edit);
        return view();
    }
    public function update(){
        $id = i('id');
        $goods = i('goods');
        $cashback = i('cashback');
        $res = model('fxGoods')->allowField(true)->where('id',$id)->update(['goods_id'=>$goods,'cashback'=>$cashback]);
        if (!empty($res)){
            $this->success('编辑成功','/admin/fx/lists');
        }
        $this->error('编辑失败');
        return view ();
    }

    public function del(){
        $id = i('id');
        $mod=model('fxGoods')->where("goods_id",$id)->delete();
        if(empty($mod)){
            $this->error("数据不存在");
        }
        $this->success("删除成功","/admin/fx/lists");
    }

    public function talklists(){
        $list = model('fxTalk')->where("status",0)->join('user','fx_talk.user_id = user.id',"left")->order("time desc")->paginate();
        $this->assign("list",$list);
        return view();
    }
    public function talkconfirm(){
        $orderno=i("orderno","请输入提款单号");
        $fxtalk=model('fxTalk')->where("orderno",$orderno)->find();
        if($fxtalk['status']!=0){
            e("提款单状态不允许确认");
        }
        model('fxTalk')->where("orderno",$orderno)->update(['status'=>1]);
        model('fxTalk')->where("orderno",$orderno)->update(['dotime'=>getMillisecond()]);
        $this->success("确认成功");
    }
    public function talkcancel(){
        $orderno=i("orderno","请输入提款单号");
        $fxtalk=model('fxTalk')->where("orderno",$orderno)->find();
        if($fxtalk['status']!=0){
            e("提款单状态不允许驳回");
        }
        model('fxTalk')->where("orderno",$orderno)->update(['status'=>2]);
        fxmoney($fxtalk['user_id'],$fxtalk['money'],"提款单:{$orderno}驳回");
        $this->success("驳回成功");
    }
    public function add(){
        return view();
    }

    public function add_to(){
        $data = $_POST;
        if (!empty($data)){
            $list = model('fxGoods')->insert($data);
        }
        if ($list){
            $this->success('数据添加成功!','/admin/fx/lists');
        }
        return view();
    }
}
